<script setup lang="ts">
import { Pod } from "@/views/domain/kubeHud/api/k8s/types";
import { IconPackage } from "@/views/domain/kubeHud/views/k8s/components/icons";
import { isPodRunning } from "@/views/domain/kubeHud/utils";

type Prop = {
  pod?: Pod;
};

defineProps<Prop>();
</script>

<template>
  <div class="container-badge">
    <el-icon size="32">
      <IconPackage />
    </el-icon>
    <div
      :class="['badge', isPodRunning(pod.status?.phase, 'ready', 'not-ready')]"
    />
  </div>
</template>
<style lang="scss" scoped>
.container-badge {
  display: flex;
  position: relative;

  .badge {
    position: absolute;
    bottom: 0;
    left: 32px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
  }

  .ready {
    background-color: var(--el-color-success);
  }

  .not-ready {
    background-color: var(--el-color-danger);
    animation: blink-and-change-color 2s infinite ease-in-out;
  }

  @keyframes blink-and-change-color {
    /* 动画开始时的状态，文字完全显示，颜色为红色 */
    0% {
      opacity: 1;
      background-color: var(--el-color-danger);
    }
    /* 动画进行到50%时的状态，文字完全隐藏，颜色为蓝色 */
    50% {
      opacity: 0.5;
      background-color: var(--el-color-danger);
    }
    /* 动画结束时的状态，文字完全显示，颜色为红色 */
    100% {
      opacity: 1;
      background-color: var(--el-color-danger);
    }
  }
}
</style>
